package flc.ast.fragment;

import androidx.fragment.app.Fragment;

import android.view.View;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.R;
import flc.ast.activity.ProRecordActivity;
import flc.ast.activity.SelAudioActivity;
import flc.ast.activity.SelPicActivity;
import flc.ast.activity.SelVideoActivity;
import flc.ast.databinding.FragmentHomeBinding;
import flc.ast.dialog.DeviceDialog;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link HomeFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HomeFragment extends BaseNoModelFragment<FragmentHomeBinding> {

    private DeviceDialog deviceDialog;

    @Override
    protected int onCreate() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.ivChangeDevice.setOnClickListener(this);
        mDataBinding.ivLocalVideo.setOnClickListener(this);
        mDataBinding.ivLocalAudio.setOnClickListener(this);
        mDataBinding.ivLocalPicture.setOnClickListener(this);
        mDataBinding.ivProRecord.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        int id = v.getId();
        if (id == R.id.ivChangeDevice) {//更换设备
            showDeviceDialog();
        } else if (id == R.id.ivLocalVideo) {//本地视频
            if (!Content.IsConnect) {
                ToastUtils.showShort(R.string.please_conn_pro_device);
                return;
            }
            startActivity(SelVideoActivity.class);
        } else if (id == R.id.ivLocalAudio) {//本地音频
            if (!Content.IsConnect) {
                ToastUtils.showShort(R.string.please_conn_pro_device);
                return;
            }
            startActivity(SelAudioActivity.class);
        } else if (id == R.id.ivLocalPicture) {//本地图片
            if (!Content.IsConnect) {
                ToastUtils.showShort(R.string.please_conn_pro_device);
                return;
            }
            startActivity(SelPicActivity.class);
        } else if (id == R.id.ivProRecord) {//投屏记录
            startActivity(ProRecordActivity.class);
        }
    }

    @Override
    protected void initData() {

    }

    private void isConnect() {
        if (Content.IsConnect) {
            mDataBinding.tvDevice.setText(Content.ConnectName);
        } else {
            mDataBinding.tvDevice.setText(getString(R.string.not_conn_device));
        }
    }

    private void showDeviceDialog() {
        if (deviceDialog == null) {
            deviceDialog = new DeviceDialog(mContext);
        }
        deviceDialog.setListener(new DeviceDialog.Ilistener() {
            @Override
            public void clickItem() {
                isConnect();
            }
        });
        deviceDialog.show();
    }

}